package pluginUtils;

public class SphereInversion {

	private Sphere ci;
	private Pos3D center; 
	private double radius; 
	
	public SphereInversion(Sphere ci) {
		this.ci = ci;
		this.center=ci.getCenter();
		this.radius=ci.getRadius(); 
	}
	
	public String toString(){
		return "Invertor "+ci;  
	}

	public Sphere inverte(Sphere c){
		double dist=Pos3D.distance(c.getCenter(),this.center); 
		double powerO=dist*dist-c.getRadius()*c.getRadius(); 
		double alpha=this.radius*this.radius/powerO; 
		double rayon=Math.abs(alpha*c.getRadius());
		
		double x=center.getX()+alpha*(c.getCenter().getX()-center.getX());
		double y=center.getY()+alpha*(c.getCenter().getY()-center.getY());
		double z=center.getZ()+alpha*(c.getCenter().getZ()-center.getZ());
		Pos3D centre=new Pos3D(x,y,z); 
		Sphere result=new Sphere(centre,rayon); 
		result.setColorIndex(c.getColorIndex());
		return result; 
	}
	
	
	
	/**
	 * @return the center
	 */
	public Pos3D getCenter() {
		return center;
	}

	/**
	 * @param center the center to set
	 */
	public void setCenter(Pos3D center) {
		this.center = center;
	}

	/**
	 * @return the ci
	 */
	public Sphere getCi() {
		return ci;
	}

	/**
	 * @param ci the ci to set
	 */
	public void setCi(Sphere ci) {
		this.ci = ci;
	}

	/**
	 * @return the radius
	 */
	public double getRadius() {
		return radius;
	}

	/**
	 * @param radius the radius to set
	 */
	public void setRadius(double radius) {
		this.radius = radius;
	}

}
